package com.cangxuan.manage.controller;

import com.cangxuan.manage.annotation.Check;
import com.cangxuan.manage.annotation.check.Max;
import com.cangxuan.manage.annotation.check.NotNull;
import com.cangxuan.manage.bean.Page;
import com.cangxuan.manage.entity.Order;
import com.cangxuan.manage.entity.Registration;
import com.cangxuan.manage.service.IOrderService;
import io.swagger.annotations.*;
import lombok.Data;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游星宇
 * 一级市场订单相关控制器
 */
@Api(tags = "订单相关接口")
@RestController
@RequestMapping("order")
public class OrderController extends BaseController{
    IOrderService iOrderService;
    @Autowired
    public void setiOrderService(IOrderService iOrderService) {
        this.iOrderService = iOrderService;
    }

   /* @Data
    @ApiModel("一级市场订单实体")
    public static class orderBody1{
        @ApiModelProperty("藏品名称")
        String name;
        @ApiModelProperty("订单状态")
        String orderformStateName;
        @ApiModelProperty("买方用户id")
        Integer buyerId;
    }


    @PostMapping("dd1")
    @ApiOperation("一级市场订单")
    public Object get1(@RequestBody orderBody1 orderBody) {
        List<Order> orderList1 = iOrderService.select1(orderBody.getName(),
                orderBody.getOrderformStateName(),
                orderBody.getBuyerId());
        return success(orderList1);
    }

    @Data
    @ApiModel("二级市场订单实体")
    public static class orderBody2{
        @ApiModelProperty("藏品名称")
        String name;
        @ApiModelProperty("订单状态")
        String orderformStateName;
        @ApiModelProperty("卖方用户id")
        Integer sellerId;
        @ApiModelProperty("买方用户id")
        Integer buyerId;
    }

    @PostMapping("dd2")
    @ApiOperation("二级市场订单")
    public Object get2(@RequestBody orderBody2 orderBody) {
        List<Order> orderList2 = iOrderService.select2(orderBody.getName(),
                orderBody.getOrderformStateName(),
                orderBody.getSellerId(),
                orderBody.getBuyerId());
        return success(orderList2);
    }*/

    @Data
    @ApiModel("一级市场定单分页查询body")
    public static class OrderPageBody{
        @ApiModelProperty("页码，从1开始")
        @NotNull(message = "请传递pageIndex")
        Integer pageIndex;
        @ApiModelProperty("页大小，就是每页查询的数量，最大为50条")
        @Max(value = 50, message = "pageSize不能大于50")
        Integer pageSize = 10;
        @ApiModelProperty("藏品名称")
        String name;
        @ApiModelProperty("订单状态")
        String orderformStateName;
        @ApiModelProperty("用户Id")
        Integer buyerId;
    }

    /**
     *一级市场定单分页
     * @param orderPageBody
     * @return
     */
    @PostMapping
    @ApiOperation("一级市场挂单分页查询")
    public Object page1( @RequestBody OrderController.OrderPageBody orderPageBody) {
        Page<Order> orderPage = iOrderService.page1(orderPageBody.getPageIndex(),
                orderPageBody.getPageSize(),
                orderPageBody.getName(),
                orderPageBody.getOrderformStateName(),
                orderPageBody.getBuyerId());
        return success(orderPage);
    }

    @Data
    @ApiModel("二级市场定单分页查询body")
    public static class OrderPageBody2{
        @ApiModelProperty("页码，从1开始")
        @NotNull(message = "请传递pageIndex")
        Integer pageIndex;
        @ApiModelProperty("页大小，就是每页查询的数量，最大为50条")
        @Max(value = 50, message = "pageSize不能大于50")
        Integer pageSize = 10;
        @ApiModelProperty("藏品名称")
        String name;
        @ApiModelProperty("订单状态")
        String orderformStateName;
        @ApiModelProperty("卖方Id")
        Integer sellerId;
        @ApiModelProperty("买方用户Id")
        Integer buyerId;
    }

    /**
     *一级市场定单分页
     * @param orderPageBody2
     * @return
     */
    @PostMapping("2")
    @ApiOperation("二级市场挂单分页查询")
    public Object page2(@Check @RequestBody OrderController.OrderPageBody2 orderPageBody2) {
        Page<Order> orderPage2 = iOrderService.page2(orderPageBody2.getPageIndex(),
                orderPageBody2.getPageSize(),
                orderPageBody2.getName(),
                orderPageBody2.getOrderformStateName(),
                orderPageBody2.getSellerId(),
                orderPageBody2.getBuyerId());
        return success(orderPage2);
    }

}
